package com.fbs.wowo.forum.web;

import com.fbs.wowo.base.BaseController;
import com.fbs.wowo.base.Response;
import com.fbs.wowo.forum.entity.Comments;
import com.fbs.wowo.forum.service.CommentsService;
import com.fbs.wowo.forum.vo.CommentsList;
import com.fbs.wowo.forum.vo.CommentsListQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/comments")
public class CommentsController extends BaseController {

    @PostMapping("/add")
    public Response addComment(@ModelAttribute Comments comments) {
        return success(commentsService.add(comments));
    }

    @PostMapping("/del")
    public Response del(@RequestParam String commentsId) {
        commentsService.del(commentsId);
        return success();
    }

    @GetMapping("/list")
    public Response list(@ModelAttribute CommentsListQuery query) {
        List<CommentsList> list = commentsService.list(query);
        return success(list);
    }

    @GetMapping("/count")
    public Response count(@RequestParam String entityId, @RequestParam Integer entityType) {
        return success(commentsService.count(entityId, entityType));
    }

    @Autowired
    private CommentsService commentsService;
}
